package cn.ultrarisk.scadmin.manager.biz.common.dao;

import cn.ultrarisk.mybatis.extension.domain.Page;
import cn.ultrarisk.mybatis.extension.query.Query;
import cn.ultrarisk.scadmin.manager.biz.common.entity.OperationLog;
import cn.ultrarisk.scadmin.manager.support.BaseDAO;
import org.springframework.stereotype.Repository;

/**
 * 操作日志数据操作类
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/3/28
 * @since V1.0
 */
@Repository
public class OperationLogDAO extends BaseDAO<OperationLog, Integer> {
    /**
     * 构造器
     */
    public OperationLogDAO() {
        super(OperationLog.class, OperationLog.COLUMN_PROPERTY_MAP);
    }

    public Page<OperationLog> findPage(Long optStartTime, Long optEndTime, Boolean isScheduler, int pageNo, int pageSize) {
        Query query = new Query();
        if (optStartTime != null && optStartTime > 0) {
            query.gte(OperationLog.OPT_TIME, optStartTime);
        }
        if (optEndTime != null && optEndTime > 0) {
            query.lt(OperationLog.OPT_TIME, optEndTime);
        }
        if (isScheduler != null && isScheduler) {
            query.eq(OperationLog.ADMIN_ID, 0);
        } else {
            query.neq(OperationLog.ADMIN_ID, 0);
        }
        query.addSort(OperationLog.OPT_TIME, Query.Direction.DESC);
        return findPage(query, pageNo, pageSize);
    }
}
